package com.bbcare.extendContent.zdy.service;


import com.bbcare.followup.plat.entity.PatientContentData;
import com.bbcare.followup.plat.entity.PatientTask;
import com.bbcare.followup.plat.store.ibatis.IPatientTaskContentDAO;
import com.bbcare.followup.plat.store.ibatis.IPatientTaskDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ZDYServiceImpl implements IZDYService
{
    @Autowired
    private IPatientTaskDAO iPatientTaskDAO;

    @Autowired
    private IPatientTaskContentDAO iPatientTaskContentDAO;
    @Override
    public void Day42CopyValue(Map<String, Object> param) throws Exception {



        Map<String,String> replace = new HashMap();
        replace.put("bsyletzqfzeb_jd_cc","bsyletzqfzeb_yy_chanci");
        replace.put("bsyletzqfzeb_jd_tc","bsyletzqfzeb_yy_taici");
        replace.put("bsyletzqfzeb_jd_zrfmfs","bsyletzqfzeb_yy_zrfmfs");
        replace.put("bsyletzqfzeb_jd_fmfs","bsyletzqfzeb_yy_fmfs");
        replace.put("Pub1100004","bsyletzqfzeb_yy_csrq");
        replace.put("Pub1100005","Pub1100005");
        replace.put("Pub1100006","bsyletzqfzeb_yy_tailing");
        replace.put("bsyletzqfzeb_jd_cssc","bsyletzqfzeb_yy_cssc");
        replace.put("bsyletzqfzeb_jd_cstz","bsyletzqfzeb_yy_cstz");

        Map<String,String> values = new HashMap<>();
        Map<String,Object> queryMap = new HashMap<>();
        queryMap.put("taskId",param.get("taskId").toString());
        PatientTask patientTask = iPatientTaskDAO.getPreviousTaskId(queryMap);
        if(patientTask==null||patientTask.getSeqNo()!=0){
            return;
        }
        queryMap.put("taskId",patientTask.getId());
        List<PatientContentData> list  = iPatientTaskContentDAO.selectContentDataByTaskId(queryMap);
        for (PatientContentData patientContentData:list) {
            if(replace.containsKey(patientContentData.getQuestionId())){
                values.put(replace.get(patientContentData.getQuestionId()),patientContentData.getQuestionAnswer());
            }
        }
        if(param.containsKey("values")&&((Map)param.get("values")).size()>0){
            ((Map)param.get("values")).putAll(values);
        }else{
            param.put("values",values);
        }

    }
}
